﻿using Microsoft.Xna.Framework.Input;
using OilRigSumoWrestlers.Commands;
using RaptorEngine.Managers;

namespace OilRigSumoWrestlers.KeyBindings
{
    /// <summary>
    /// Sets the default keyboard bindings for the specified player.
    /// </summary>
    class PlayerKeyboardBindings : KeyBindingCollection
    {
        public PlayerKeyboardBindings(LogicalPlayerIndex player)
        {
            if (player.Equals(LogicalPlayerIndex.One))
            {
                PlayerOneBindings(player);
            }
            else if (player.Equals(LogicalPlayerIndex.Two))
            {
                PlayerTwoBindings(player);
            }
        }

        private void PlayerOneBindings(LogicalPlayerIndex player)
        {
            //Left
            bindings.Add(GameConstant.LEFT + player.ToString(), new MoveCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Left
            });
            //Right
            bindings.Add(GameConstant.RIGHT + player.ToString(), new MoveCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Right
            });
            //Up
            bindings.Add(GameConstant.UP + player.ToString(), new MoveCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Up
            });

            //Down
            bindings.Add(GameConstant.DOWN + player.ToString(), new MoveCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Down
            });
            //Menu
            bindings.Add(GameConstant.MENU + player.ToString(), new UseCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Escape
            });
            //Push
            bindings.Add(GameConstant.PUSH + player.ToString(), new UseCommand()
            {
                LogicalPlayer = player,
                Key = Keys.NumPad0
            });

            //Menu Forward
            bindings.Add(GameConstant.MENU_FORWARD + player.ToString(), new UseCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Enter
            });

            //Menu Back
            bindings.Add(GameConstant.MENU_BACK + player.ToString(), new UseCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Escape
            });

            //Menu Next
            bindings.Add(GameConstant.MENU_NEXT + player.ToString(), new UseCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Down
            });

            //Menu Previous
            bindings.Add(GameConstant.MENU_PREVIOUS + player.ToString(), new UseCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Up
            });
        }

        private void PlayerTwoBindings(LogicalPlayerIndex player)
        {
            //Left
            bindings.Add(GameConstant.LEFT + player.ToString(), new MoveCommand()
            {
                LogicalPlayer = player,
                Key = Keys.A
            });
            //Right
            bindings.Add(GameConstant.RIGHT + player.ToString(), new MoveCommand()
            {
                LogicalPlayer = player,
                Key = Keys.D
            });
            //Up
            bindings.Add(GameConstant.UP + player.ToString(), new MoveCommand()
            {
                LogicalPlayer = player,
                Key = Keys.W
            });
            //Down
            bindings.Add(GameConstant.DOWN + player.ToString(), new MoveCommand()
            {
                LogicalPlayer = player,
                Key = Keys.S
            });

            //Menu
            bindings.Add(GameConstant.MENU + player.ToString(), new UseCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Tab
            });
            //Push
            bindings.Add(GameConstant.PUSH + player.ToString(), new UseCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Space
            });

            //Menu Forward
            bindings.Add(GameConstant.MENU_FORWARD + player.ToString(), new UseCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Enter
            });

            //Menu Back
            bindings.Add(GameConstant.MENU_BACK + player.ToString(), new UseCommand()
            {
                LogicalPlayer = player,
                Key = Keys.Tab
            });

            //Menu Next
            bindings.Add(GameConstant.MENU_NEXT + player.ToString(), new UseCommand()
            {
                LogicalPlayer = player,
                Key = Keys.S
            });

            //Menu Previous
            bindings.Add(GameConstant.MENU_PREVIOUS + player.ToString(), new UseCommand()
            {
                LogicalPlayer = player,
                Key = Keys.W
            });
        }

    }
}
